#include "predicates.h"
#include <vector>
#include <iostream>

class random_input
{
   int seed;
   static const int a = 1664525;
   static const int c = 1013904223;
public:
   random_input(int seed) 
      :seed(seed)
   {}

   int get_int() 
   {
      return (seed = seed * a + c) & 0x7fffffff;
   }

   double get_double() 
   {
      static const double lo = -1000;
      static const double hi = 1000;
      static const double scale = 1. / (1 << 30);
      return (lo + (hi - lo) * scale * (get_int() & 0x3fffffff));
   }
};

int get_result(std::vector<bool> const & intersects) {
   int p = 1;
   int res = 0;
   for (size_t i = 0; i < intersects.size(); ++i, p *= 239) {
      if (intersects[i]) {
         res += p;
      }
   }
   return res;
}

int main() {
   int t; size_t n;
   std::cin >> n >> t;

   vect v1,v2;
   std::vector<bool> intersects;

   if (t == 0) {
      for (size_t i = 0; i < n; ++i) {
         std::cin >> v1.a.x >> v1.a.y >> v1.b.x >> v1.b.y;
         std::cin >> v2.a.x >> v2.a.y >> v2.b.x >> v2.b.y;

         intersects.push_back(((left_turn(v1,v2.a) * left_turn(v1,v2.b) <= 0) && (left_turn(v2,v1.a) * left_turn(v2,v1.b) <= 0) && bounding_box(v1,v2)));
      }
      std::cout << get_result(intersects);
   } else {
      int seed;
      std::cin >> seed;
      random_input random_gen(seed);

      for (size_t i = 0; i < n; ++i) {
         v1.a.x = random_gen.get_double(); v1.a.y = random_gen.get_double();
         v1.b.x = random_gen.get_double(); v1.b.y = random_gen.get_double();
         v2.a.x = random_gen.get_double(); v2.a.y = random_gen.get_double();
         v2.b.x = random_gen.get_double(); v2.b.y = random_gen.get_double();

         intersects.push_back(((left_turn(v1,v2.a) * left_turn(v1,v2.b) <= 0) && (left_turn(v2,v1.a) * left_turn(v2,v1.b) <= 0) && bounding_box(v1,v2)));
      }
      std::cout << get_result(intersects);
   }
}